package JianZhiOffer;


/**
 * 把空格替换成%20
 *
 * replaceAll
 * stringBuilder
 * newChars
 * */
class Solution05 {

    public static void main(String[] args) {
        String s = "We are happy.";

        char[] chars = s.toCharArray();

        char[] newChars = new char[3 * chars.length];
        int index = 0;

        for (int i = 0; i < chars.length; i++) {
            if (Character.isSpace(chars[i])) {
                newChars[index] = '%';
                newChars[index + 1] = '2';
                newChars[index + 2] = '0';
                index = index + 3;
            } else {
                newChars[index] = chars[i];
                index++;
            }
        }

        String newStr = new String(newChars, 0, index);
        System.out.println(newStr);
    }
}